<%--
  Created by IntelliJ IDEA.
  User: Tolean
  Date: 2018/5/30
  Time: 17:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Lyon-Admin</title>
    <%@include file="common/head.jspf"%>
    <link rel="Shortcut Icon" href="${lyon}/static/images/favicon.ico"  />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="${lyon}/interface/admin/common/layui/css/font.css">
    <link rel="stylesheet" href="${lyon}/interface/admin/common/layui/css/xadmin.css">
    <script type="text/javascript" src="${lyon}/static/assets/js/jquery.min.js"></script>
    <script src="${lyon}/interface/admin/common/layui/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${lyon}/interface/admin/common/layui/js/xadmin.js"></script>

    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/static/baiduUE/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/static/baiduUE/ueditor.all.min.js"></script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/static/baiduUE/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<div class="x-body">
    <form action="" method="post" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label for="title" class="layui-form-label">
                <span class="x-red">*</span>博客标题
            </label>
            <div class="layui-input-inline">
                <input type="text" id="title" name="title" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="type_id" class="layui-form-label">
                <span class="x-red">*</span>所属分类
            </label>
            <div class="layui-input-inline">
                <select id="type_id" name="type_id" class="valid">
                    <c:forEach items="${blogTypes}" var="i">
                        <option value="${i.id}">${i.type_name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="sign" class="layui-form-label">
               博客标语
            </label>
            <div class="layui-input-block">
                <input type="text" id="sign" name="sign" placeholder="未填写则默认使用用户签名"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="content" class="layui-form-label">
                <span class="x-red">*</span>博客正文
            </label>
            <div class="layui-input-block">
                <script id="content" name="content" type="text/plain"></script>
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label">博客状态</label>
            <div class="layui-input-block">
                <input type="radio" name="statu" value="1" title="所有人可见" checked>
                <input type="radio" name="statu" value="2" title="仅自己可见">
                <input type="radio" name="statu" value="0" title="所有人都不可见">
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit="" lay-filter="add">增加</button>
        </div>
    </form>
</div>
<script>
    var editor = UE.getEditor('content');
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;
        //监听提交
        form.on('submit(add)', function(data){
            //手动验证UE内容是否为空
            var content=UE.getEditor('content').getContent();
            if(content==null||content==""){
                layer.msg("博客正文不能为空",{icon:5,time:1000});
                return false;
            }
            var params=data.field;
            params['summary'] = UE.getEditor('content').getContentTxt().substr(0,200);
            //alert(JSON.stringify(params));
            $.post("${lyon}/admin/addBlog.do",params,function (result) {
                if(result.success){
                    layer.alert("增加成功", {icon: 6},function () {
                        //alert(window.parent.location.pathname);
                        if(window.parent.location.pathname=="/admin/blogList.html"){
                            window.parent.location.reload();
                        }
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                }else{
                    layer.msg("抱歉,添加失败!",{icon:2,time:1000});
                }
            },"json");
            return false;
        });
    });
</script>
</body>
</html>